package pig

import (
	"context"
	"net/http"

	"github.com/gorilla-go/container"
	"github.com/gorilla-go/pig/constant"
)

// 获取请求
func GetRequest(ctx context.Context) *http.Request {
	c := ctx.Value(constant.Container).(*container.Container)
	return container.GetMustSingletonByAlias[*http.Request](c, constant.Request)
}

// 获取响应
func GetResponseWriter(ctx context.Context) http.ResponseWriter {
	return container.GetMustImplement[http.ResponseWriter](
		ctx.Value(constant.Container).(*container.Container),
	)
}

// 获取容器
func Container(ctx context.Context) *container.Container {
	return ctx.Value(constant.Container).(*container.Container)
}
